﻿<#include "include/_meta.html">
<title>角色列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 角色管理 <span class="c-gray en">&gt;</span> 角色列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
		<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
		<a href="javascript:;" onclick="admin_add('添加角色','/addrole','1000','600')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a>
	</span>  </div>
	<table id="userListTable" class="table table-border table-bordered table-bg table-hover">
		<thead>
			<tr>
				<th scope="col" colspan="9">账户列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="useritem" value=""></th>
				<th width="150">编号</th>
				<th width="90">角色编号</th>
				<th width="150">角色名称</th>
				<th width="130">角色描述</th>
				<th width="100">是否已启用</th>
				<th width="25">操作</th>
			</tr>
			
			<#list roles as role>
				<tr class="text-c">
				<th width="25"><input type="checkbox" name="useritem" value="${(role.roleId)!""}"></th>
				<th width="150">${role_index}</th>
				<th width="100">${(role.roleId)!""}</th>
				<th width="150">${(role.roleName)!""}</th>
				<th width="150">${(role.discribe)!""}</th>
				
<#if role.isabled==1>
					<th width="130">
						<span class="label label-success radius ">已启用</span>
					</th>
					<th  width="25">
						<a title="编辑" href="javascript:;" onclick="role_edit('角色编辑','/editrole?roleId=${(role.roleId)!''}','2','1000','600')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>"
		          		<a style='text-decoration:none' onClick="role_stop(this,${(role.roleId)!''})" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
					</th>
					
<#else>
					<th width="130">
						<span class="label radius ">已停用</span>
					</th>
					<th  width="25">
						<a title="编辑" href="javascript:;" onclick="role_edit('角色编辑','/editrole?roleId=${(role.roleId)!''}','2','800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>"
						<a style='text-decoration:none' onClick="role_start(this,${(role.roleId)!''})" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>
					</th>
</#if>
				
				
				
				</tr>

			</#list>
		</thead>
		<tbody>

		</tbody>
	</table>
</div>

<#include "include/_footer.html">

<script type="text/javascript">

var datadel = function(){
	
	//判断选择项是否为空
	var checkedNum = $("input[name='useritem']:checked").length;
	if(checkedNum==0){
		layer.msg('请选中要删除的列表项!',{icon: 5,time:1000});
		return;
	}
	//获取选择项的值
	var checkedVal = "";
	$("input[name='useritem']:checked").each(function(){  
		checkedVal+=$(this).val()+",";  
	});
	
	var itemsTipStr = "这条记录";
	if(checkedNum>1){
		itemsTipStr = "这些选项";
	}
	
	layer.confirm('确认要删除'+itemsTipStr+'吗？',function(){
	
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
		   type: "POST",
		   url: "/delRoles",
		   data: "roleIds="+checkedVal,
		   success: function(msg){
				layer.msg('已删除!',{icon: 5,time:1000});
				window.location.reload();
		   }
		});
		

        
	});
	
	
}


/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*角色-增加*/
function admin_add(title,url,w,h){
	layer_show(title,url,w,h);
}

/*角色-删除*/
function admin_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		
		
		$.ajax({
		   type: "POST",
		   url: "/delUser",
		   data: "userid="+id,
		   success: function(msg){
		       	window.location.reload();
		   }
		});
		
		
		//$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
	});
}

/*角色-编辑*/
function role_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}

/*管理员-停用*/
function role_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		
		$.ajax({
		   type: "POST",
		   url: "/setRoleState",
		   data: "roleId="+id+"&isabled=0",
		   success: function(msg){
		       window.location.reload();
		   }
		});
		
		//$(obj).parents("tr").find(".td-manage").prepend('<a onClick="role_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
		//$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
		//$(obj).remove();
		layer.msg('已停用!',{icon: 5,time:1000});
	});
}

/*管理员-启用*/
function role_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
			
		
		$.ajax({
		   type: "POST",
		   url: "/setRoleState",
		   data: "roleId="+id+"&isabled=1",
		   success: function(msg){
		       window.location.reload();
		   }
		});
		
		
		//$(obj).parents("tr").find(".td-manage").prepend('<a onClick="role_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
		//$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
		//$(obj).remove();
		layer.msg('已启用!', {icon: 6,time:1000});
	});
}
</script>
</body>
</html>